﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebUI.DAL;
using WebUI.BL.Products;

namespace WebUI.AdminSite.Product
{
    public partial class ProductColorDetails : System.Web.UI.Page
    {
        private string id = String.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            id = Request.QueryString["Id"];
            if(!IsPostBack)
            {
                BindDate();
            }
        }

        private void BindDate()
        {
            ProductColorBL repository=new ProductColorBL();
            if(!String.IsNullOrEmpty(id))
            {
                var displayModels = repository.GetProductColorById(int.Parse(id));
                txtColorName.Text = displayModels.ColorName;
                txtDesc.Text = displayModels.ColorDesc;
                txtImg.Text = displayModels.Img;
                txtColorCode.Text = displayModels.ColorCode;
                imgColor.ImageUrl = Helpers.link.ToImages(displayModels.Img);
                drpStatus.Text = displayModels.Status;
            }
        }

        protected void BtnClickUpload(object sender, UserControls.EventUploadImg e)
        {
            txtImg.Text = e.FileName;
            imgColor.ImageUrl = Helpers.link.ToImages(e.FileName);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int no = 0;
            int.TryParse(id, out no);
            var repository = new ProductColorBL();

            var productColor = repository.GetProductColorById(no);
            if(productColor!=null)
            {
                productColor.ColorCode = txtColorCode.Text;
                productColor.ColorDesc = txtDesc.Text;
                productColor.ColorName = txtColorName.Text;
                productColor.Img = txtImg.Text;
                productColor.Status = drpStatus.SelectedValue;
            }

                                       
                                   
            repository.Update(productColor);
            Response.Redirect(Helpers.link.ToAdminProductColor("ProductColor.aspx"));
        }


    }
}